﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mvp.DTO;
using System.Web.UI.WebControls;

namespace Mvp.WebControl
{
    /*
     * 可以看到此处我们将具体工作都委托给了ListControl
     */

    public class WebLookupList : ILookupList
    {
        private ListControl _underlyingList;

        public WebLookupList(ListControl underlyingList)
        {
            _underlyingList = underlyingList;
        }

        #region ILookupList 成员

        public void Add(ILoopupDTO dto)
        {
            _underlyingList.Items.Add(new ListItem(dto.Text, dto.Value));
        }

        public void Clear()
        {
            _underlyingList.Items.Clear();
        }

        public ILoopupDTO SelectedItem
        {
            get
            {
                ListItem item = _underlyingList.SelectedItem;
                return new SimpleLoopupDTO(item.Value, item.Text);
            }
        }

        #endregion
    }
}
